import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from fidoweb.lib.base import BaseController, render, Session
from fidoweb.model.user import User, UserGroup, User_UserGroup

log = logging.getLogger(__name__)

class UserGroupController(BaseController):
	def _inGroup(self, user, userGroup) :
		while (True) :
			if (Session.query(User_UserGroup).filter_by(user_id = user.id).filter_by(userGroup_id = userGroup.id).count() > 0) :
				return True
			if (userGroup.parent_id != None) :
				userGroup = Session.query(UserGroup).filter_by(id = userGroup.parent_id).first()
			else :
				break
		return False
